<template>
  <div class="songs-container">
    <div class="tab-bar">
      <span class="item" :class="{active:tag=='0'}" @click="tag='0'">全部</span>
      <span class="item" :class="{active:tag=='7'}" @click="tag='7'">华语</span>
      <span class="item" :class="{active:tag=='96'}" @click="tag='96'">欧美</span>
      <span class="item" :class="{active:tag=='8'}" @click="tag='8'">日本</span>
      <span class="item" :class="{active:tag=='16'}" @click="tag='16'">韩国</span>
    </div>
    <!-- 底部的table -->
    <table class="el-table playlit-table">
      <thead>
        <th></th>
        <th>专辑图片</th>
        <th>音乐标题</th>
        <th>歌手</th>
        <th>专辑</th>
        
      </thead>
      <tbody>
        <tr class="el-table__row" v-for="(item,index) in list" :key="index">
          <td>{{index+1}}</td>
          <td>
            <div class="img-wrap">
              <img :src="item.album.picUrl" alt="" />
              
            </div>
          </td>
          <td>
            <div class="song-wrap">
              <div class="name-wrap">
                <span>{{item.name}}</span>
                
              </div>
              
            </div>
          </td>
          <td>{{item.artists[0].name}}</td>
          <td>{{item.album.name}}</td>
          
        </tr>
       
      </tbody>
    </table>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'songs',
  data() {
    return {
      list:[],
      tag:'96'
    };
  },
  //侦听器
  watch:{
    tag(){
      console.log(this.tag)
      this.songList();
    }
  },
  created(){
    //最新音乐数据
    this.songList();
  },
  methods:{
    //获取最新音乐数据
        songList(){
          axios({
            url: 'http://localhost:3000/top/song',
            method: 'get',
            params:{
              type:this.tag
            }
          }).then(res => {
            console.log(res);
            this.list=res.data.data;
            
          })
       },
       //播放歌曲
       startmusic(id){
           axios({
          url: 'http://localhost:3000/song/url',
          method: 'get',
          params: {
            id // id:id
          }
        }).then(res => {
          // console.log(res)
          let url = res.data.data[0].url
          // console.log(this.$parent.musicUrl)
          // 设置给父组件的 播放地址
          this.$parent.musicUrl = url
        })
       }
  }
}
</script>

<style >


</style>
